/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       materials.h

	$Header: /game/materials.h $

	$NoKeywords: $

 ************************************************************************/

#ifndef TIMED_WINDOW_H_INCLUDED
#define TIMED_WINDOW_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "game_window.h"
#include "idle_processor.h"
#include "window_handler.h"

// ------------------------------------------------------------------------
// window which appears for a fixed amount of time, and then closes itself.
// can also drift with time.
// ------------------------------------------------------------------------
class t_timed_window : public t_window, public t_idle_processor
{
public:
	t_timed_window( t_screen_point point, t_window* parent = 0, int lifetime = 5000, 
		            t_screen_point drift = t_screen_point(0,0), int drift_delay = 200 );
	t_screen_point const&	get_drift() const;
	t_screen_point			get_total_drift() const;
	void					set_drift( t_screen_point const& drift );
	void					set_end_handler( t_window_handler handler );
	virtual void			update_size();  // update size based on child windows
protected:
	virtual void  add_child( t_window* window ); // add a child window
	virtual void  on_idle();

	t_screen_point	 m_drift;
	int				 m_drift_delay;
	t_window_handler m_end_handler;
	int				 m_lifetime;
	int				 m_last_drift_time;
	int				 m_last_update;
};

inline t_screen_point const& t_timed_window::get_drift() const
{
	return m_drift;
}

inline t_screen_point t_timed_window::get_total_drift() const
{
	return m_drift * m_lifetime / m_drift_delay;
}

inline void t_timed_window::set_drift( t_screen_point const& drift ) 
{
	m_drift = drift;
}

inline void t_timed_window::set_end_handler( t_window_handler handler )
{
	m_end_handler = handler;
}

#endif // TIMED_WINDOW_H_INCLUDED